home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
cursors.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
7KB
|
291 lines
/*
* $Id: cursors.c,v 0.91 1994/02/20 00:53:29 zhao Pre-Release $
*
*. This file is part of BIT shareware package. After the two weeks of
* free evaluation period, you are encouraged (required) to register
* your copy for a small registration fee, which is $35 for personal use
* and $50 for commercial, government and institutional use.
*
* Copyright(c) 1993, 1994 by T.C. Zhao.
* All rights reserved.
*
* Permission to use, copy, and distribute this software in its entirety
* for non-commercial purposes is hereby granted, provided that the
* above shareware and copyright notices and this permission notice
* appear in all copies and their documentation.
*
* This software may be modified for your own use, but modified versions
* may not be distributed without prior consent of the author.
*
* This software is provided "as is" without expressed or implied
* warranty of any kind.
*
*.
*
* All cursor definations
*/
#if !defined(lint) && defined(F_ID)
char *id_curs = "$Id: cursors.c,v 0.91 1994/02/20 00:53:29 zhao Pre-Release $";
#endif
#include <stdio.h>
#include "ulib.h"
#include "gl/gl.h"
#include "curdef.h"
extern int is_valid_win(long);
extern void set_current_window(long);
#include "bitmaps/sfrect.cur"
#include "bitmaps/rect10.cur"
#include "bitmaps/rect20.cur"
#include "bitmaps/rect30.cur"
#include "bitmaps/scross.cur"
#include "bitmaps/rotate.cur"
#include "bitmaps/rslant.cur"
#include "bitmaps/lslant.cur"
#include "bitmaps/busy.cur"
#include "bitmaps/hand.cur"
#include "bitmaps/sdisk.cur"
#include "bitmaps/hline.cur"
#include "bitmaps/vline.cur"
#include "bitmaps/circ10.cur"
#include "bitmaps/circ20.cur"
#include "bitmaps/circ30.cur"
#include "bitmaps/circnet.cur"
typedef struct
{
unsigned short *curbits;
Cur_name name;
int type;
int hotx, hoty;
}
cur_def_t;
static cur_def_t bit_cursors[] =
{
{0, CUR_DEFAULT, C16X1, 8, 8},
{cur_scross, CUR_S_CROSS, C16X1, 8, 8},
{cur_busy, CUR_BUSY, C16X2, 8, 8},
{cur_hand, CUR_HAND, C16X2, 2, 10},
{cur_sfrect, CUR_S_FRECT, C16X1, 7, 7},
{cur_rect10, CUR_RECT10, C16X1, 7, 7},
{cur_rect20, CUR_RECT20, C32X1, 15, 15},
{cur_rect30, CUR_RECT30, C32X1, 15, 15},
{cur_lslant, CUR_L_LINE, C16X1, 7, 7},
{cur_rslant, CUR_R_LINE, C16X1, 7, 7},
{cur_sdisk, CUR_S_DISK, C16X1, 7, 7},
{cur_rot1, CUR_ROT1, C16X2, 8, 8},
{cur_rot2, CUR_ROT2, C16X2, 8, 8},
{cur_rot3, CUR_ROT3, C16X2, 8, 8},
{cur_rot4, CUR_ROT4, C16X2, 8, 8},
{cur_hline, CUR_H_LINE, C16X1, 8, 8},
{cur_vline, CUR_V_LINE, C16X1, 8, 8},
{cur_circ10, CUR_CIRC10, C16X1, 7, 7},
{cur_circ20, CUR_CIRC20, C32X1, 15, 15},
{cur_circ30, CUR_CIRC30, C32X1, 15, 15},
{cur_circnet, CUR_CIRCNET, C32X1, 15, 15},
};
static int ncursors = sizeof(bit_cursors) / sizeof(bit_cursors[0]);
/********************************************************************
* Initialize all cursors
********************************************************************/
void
init_cursor(void)
{
static int cur_init;
int mcol;
cur_def_t *curs = bit_cursors + 1, *curs_end = bit_cursors + ncursors;
if (cur_init)
return;
/* multi-colored cursor supported ? */
mcol = getgdesc(GD_BITS_CURSOR) > 1;
drawmode(CURSORDRAW);
mapcolor(2, 255, 255, 255);
for (; curs < curs_end; curs++)
{
curstype(curs->type);
defcursor(curs->name, curs->curbits);
curorigin(curs->name, curs->hotx, curs->hoty);
}
drawmode(NORMALDRAW);
}
/*****************************************************************
* Get current cursor index
****************************************************************/
static int
get_cursor(void)
{
short ci;
Colorindex g1, g2;
Boolean b;
getcursor(&ci, &g1, &g2, &b);
return ci;
}
void
set_cursor(long win, int n)
{
if (n >= 0 && win > 0)
{
set_current_window(win);
if (get_cursor() != n)
setcursor(n, 1, 0);
}
}
/**********************************************************************
* Default cursors for windows that have a fixed durations
* or windows whose default cursor is different from that of the
* system
**********************************************************************/
#define MAXFCUR 8
static struct Fixcur
{
long wid;
int cnum;
}
fixcur[MAXFCUR];
void
set_default_cursor(long win, int n)
{
struct Fixcur *fc = fixcur + MAXFCUR;
/* search for availabel slots */
while (--fc >= fixcur && fc->wid != win && is_valid_win(fc->wid))
;
if (fc < fixcur)
{
M_warn("DefCursor", "Unable to set cursor for Wid=%ld", win);
return;
}
fc->wid = win;
fc->cnum = n;
}
/***********************************************************************
* Set the curosr to default, either the one set by set_cursor_default,
* or system default if none is set
**********************************************************************/
void
reset_cursor(long win)
{
struct Fixcur *fc = fixcur + MAXFCUR;
int n;
if (win <= 0)
return; /* need this check */
while (--fc >= fixcur && win - fc->wid)
;
n = (fc < fixcur) ? CUR_DEFAULT : fc->cnum;
set_cursor(win, n);
}
/*************************************************************************
* misc. cursor routines
***********************************************************************/
/******* Change cursor color: index 1 only ***************/
void
set_cursor_color(int *c)
{
drawmode(CURSORDRAW);
mapcolor(1, c[0], c[1], c[2]);
drawmode(NORMALDRAW);
}
void
get_cursor_color(int *c)
{
short cs[3];
drawmode(CURSORDRAW);
getmcolor(1, cs, cs + 1, cs + 2);
drawmode(NORMALDRAW);
c[0] = cs[0];
c[1] = cs[1];
c[2] = cs[2];
}
int
rotate_circle_cursor(long win)
{
static int cur_cur;
cur_cur++;
if ((cur_cur < CUR_ROT1) || (cur_cur > CUR_ROT4))
cur_cur = CUR_ROT1;
set_cursor(win, cur_cur);
return cur_cur;
}
#if 0 /* Not finished yet *{* */
/* set (15-x)'s bit to 1: short counts from zero, but cursor defines
* coutns from bit 15
*/
#define set_bit(s, x) ((s) |= (1 << (15-(x))))
/*** Make specialized cursors on the fly ***/
int
make_cursor(int type, int size)
{
static unsigned short cur_defs[2 * 32];
static int nextcn = CUR_FREE1;
int i, cn, off1;
cn = nextcn;
if (size > 32)
size = 32;
for (i = 0; i < 32; i += 2)
cur_defs[i] = cur_defs[i + 1] = 0;
off1 = (32 - size) / 2;
switch (type)
{
case FREE_L_SLANT:
default:
fprintf(stderr, "size=%d off1=%d\n", size, off1);
for (i = off1; i < off1 + size; i++)
{
if (i < 16)
set_bit(cur_defs[i * 2], i);
else
set_bit(cur_defs[i * 2 + 1], i - 16);
}
break;
}
/* define this cursor */
curstype(C32X1);
defcursor(cn, cur_defs);
curorigin(cn, 15, 15);
/* alternate between free1 & free2 */
nextcn = (cn == CUR_FREE1) ? CUR_FREE2 : CUR_FREE1;
return cn;
}
#endif /*** } **/